const app = getApp()
Page({
    data: {
        movies: [],
        application: [],
        offlineapplication: []
    },
    onLoad: function() {
        var _this = this;
        var token = wx.getStorageSync('token');
        app.data.tokenID = token
        wx.request({
            url: app.data.api + 'userinfo/info',
            data: {
                token: token
            },
            method: "GET",
            header: {
                'content-type': 'application/text'
            },
            success: function(res) {
                app.data.username = res.data.data.mobile,
                    app.data.department = res.data.data.department,
                    app.data.position = res.data.data.position,
                    app.data.realname = res.data.data.realname,
                    app.data.header = res.data.data.header,
                    app.data.messageShowRedDot = res.data.data.messageShowRedDot
            }
        })
        wx.request({
            url: app.data.api + 'index/getBanners',
            data: {
                token: token
            },
            method: "GET",
            header: {
                'content-type': 'application/text'
            },
            success: function(res) {
                var moviesarr = [];
                for (var i = 0; i < res.data.data.length; i++) {
                    moviesarr.push(res.data.data[i].imgurl)
                }
                _this.setData({
                    movies: moviesarr
                })
            }
        })

    },
    onShow() {
        var _this = this;
        wx.request({
            url: app.data.api + 'index/getMenu',
            data: {
                token: app.data.tokenID
            },
            method: "GET",
            header: {
                'content-type': 'application/text'
            },
            success: function(res) {
                _this.setData({
                    application: res.data.data.application,
                    offlineapplication: res.data.data.offlineapplication
                })
            }
        })
    },
    scanAQRcode: function(event) {
        var code = event.currentTarget.dataset.code;
        if (code == 1000) {
            wx.scanCode({
                success: (res) => {
                    if (res.result != '') {
                        wx.request({
                            url: app.data.api + 'offline/scansignin',
                            data: {
                                "offid": res.result,
                                "token": app.data.tokenID
                            },
                            method: "POST",
                            header: {
                                'content-type': 'application/x-www-form-urlencoded'
                            },
                            success: function(res) {
                                if (res.data.status) {
                                    wx.showModal({
                                        title: '提示',
                                        confirmColor: '#04A9F4',
                                        showCancel: false,
                                        content: res.data.msg,
                                        success: function(res) {
                                            if (res.confirm) {}
                                        }
                                    })
                                } else {
                                    wx.showModal({
                                        title: '提示',
                                        confirmColor: '#04A9F4',
                                        showCancel: false,
                                        content: res.data.msg,
                                        success: function(res) {
                                            if (res.confirm) {}
                                        }
                                    })
                                }
                            }
                        })
                    }
                }
            })
        }
    },
    onShareAppMessage: function() {
        return {
            title: '为企业量身定制的线上培训平台，助力企业腾飞',
            desc: '首选博志成企训营,满足企业学习落地,知识管理,等强大的线上平台功能',
            imageUrl: 'http://bonzer.dichanxuetang.com/images/wxshow.png',
            path: 'pages/login/login'
        }
    }
})